module('framework.helper.gohelper', package.seeall)

---@class gohelper
local gohelper = {}

gohelper.Type_Image = typeof(UnityEngine.UI.Image)
gohelper.Type_Text = typeof(UnityEngine.UI.Text)
gohelper.Type_TextMesh = typeof(TMPro.TextMeshProUGUI)
gohelper.Type_RawImage = typeof(UnityEngine.UI.RawImage)
gohelper.Type_Toggle = typeof(UnityEngine.UI.Toggle)
gohelper.Type_ToggleGroup = typeof(UnityEngine.UI.ToggleGroup)
gohelper.Type_Graphic = typeof(UnityEngine.UI.Graphic)
gohelper.Type_CanvasRenderer = typeof(UnityEngine.CanvasRenderer)
gohelper.Type_GridLayoutGroup = typeof(UnityEngine.UI.GridLayoutGroup)
gohelper.Type_HorizontalLayoutGroup = typeof(UnityEngine.UI.HorizontalLayoutGroup)
gohelper.Type_VerticalLayoutGroup = typeof(UnityEngine.UI.VerticalLayoutGroup)

---@type UnityEngine.GameObject
local UnityEngine_GameObject = UnityEngine.GameObject
---@type Framework.GameObjectHelper
local GameObjectHelper = Framework.GameObjectHelper
---@type Framework.UGUI.ButtonWrap
local ButtonWrap = Framework.UGUI.ButtonWrap
---@type Framework.UGUI.InputFieldWrap
local InputFieldWrap = Framework.UGUI.InputFieldWrap
---@type Framework.UGUI.ScrollRectWrap
local ScrollRectWrap = Framework.UGUI.ScrollRectWrap
---@type Framework.UGUI.SliderWrap
local SliderWrap = Framework.UGUI.SliderWrap
---@type Framework.UGUI.ToggleWrap
local ToggleWrap = Framework.UGUI.ToggleWrap
---@type Framework.UGUI.SingleImage
local SingleImage = Framework.UGUI.SingleImage
---@type Framework.UGUI.UIClickListener
local UIClickListener = Framework.UGUI.UIClickListener
local TMPDropdownWrap = Framework.UGUI.TMPDropdownWrap

---@param gameObject UnityEngine.GameObject
function gohelper.isNil(gameObject)
    return gameObject == nil or gameObject:Equals(nil)
end

---@param go UnityEngine.GameObject
function gohelper.destroy(go)
    if not gohelper.isNil(go) then
        UnityEngine_GameObject.Destroy(go)
    end
end

---@param parentGO UnityEngine.GameObject
---@param childGO UnityEngine.GameObject
function gohelper.addChild(parentGO, childGO)
    GameObjectHelper.AddChild(parentGO, childGO)
end

---@param go UnityEngine.GameObject
function gohelper.destroyAllChildren(go)
    GameObjectHelper.DestroyAllChildren(go)
end

---@param go_comp UnityEngine.Component
---@param isActive boolean
function gohelper.setActive(go_comp, isActive)
    return GameObjectHelper.SetActive(go_comp, isActive and true or false)
end

---@param go UnityEngine.GameObject
function gohelper.setAsFirstSibling(go)
    GameObjectHelper.SetAsFirstSibling(go)
end

---@param go UnityEngine.GameObject
function gohelper.setAsLastSibling(go)
    GameObjectHelper.SetAsLastSibling(go)
end

---@param go UnityEngine.GameObject
---@param index number
function gohelper.setSibling(go, index)
    GameObjectHelper.SetSibling(go, index)
end

---@param go UnityEngine.GameObject
---@return number
function gohelper.getSibling(go)
    return GameObjectHelper.GetSibling(go)
end

---@param go UnityEngine.GameObject
---@param otherGO UnityEngine.GameObject
function gohelper.setSiblingBefore(go, otherGO)
    return GameObjectHelper.SetSiblingBefore(go, otherGO)
end

---@param go UnityEngine.GameObject
---@param otherGO UnityEngine.GameObject
function gohelper.setSiblingAfter(go, otherGO)
    return GameObjectHelper.SetSiblingAfter(go, otherGO)
end

-- 设置层级
---@go  UnityEngine.GameObject
---@param layer number 层级名字
---@param recursive boolean 是否修改子物体
function gohelper.setLayer(go, layer, recursive)
    GameObjectHelper.SetLayer(go, layer, recursive)
end

-- 设置tag
---@param go UnityEngine.GameObject
---@param tag string
---@param recursive boolean 是否修改子物体
function gohelper.setTag(go, tag, recursive)
    GameObjectHelper.SetTag(go, tag, recursive)
end

----获取Unity对象的接口------------------------------------------begin
---@param name string
---@return UnityEngine.GameObject
function gohelper.find(name)
    return UnityEngine_GameObject.Find(name)
end

---@param parentGO UnityEngine.GameObject
---@param childPath string
---@return UnityEngine.GameObject
function gohelper.findChild(parentGO, childPath)
    return GameObjectHelper.FindChild(parentGO, childPath)
end

---@param parentGO UnityEngine.GameObject
---@param childPath string
---@param componentType System.Type
---@return UnityEngine.Component
function gohelper.findChildComponent(parentGO, childPath, componentType)
    return GameObjectHelper.FindChildComponent(parentGO, childPath, componentType)
end

---@param go_comp UnityEngine.Component
---@param componentType System.Type
---@return UnityEngine.Component
function gohelper.onceAddComponent(go_comp, componentType)
    return GameObjectHelper.OnceAddComponent(go_comp, componentType)
end

---@param parentGO UnityEngine.GameObject
---@param childPath string
---@return UnityEngine.UI.Text | TMPro.TextMeshProUGUI
function gohelper.findChildText(parentGO, childPath)
    return gohelper.findChildComponent(parentGO, childPath, gohelper.Type_TextMesh) or
               gohelper.findChildComponent(parentGO, childPath, gohelper.Type_Text)
end

---@param parentGO UnityEngine.GameObject
---@param childPath string
---@return TMPro.TextMeshProUGUI
function gohelper.findChildTextMesh(parentGO, childPath)
    return gohelper.findChildComponent(parentGO, childPath, gohelper.Type_TextMesh)
end

---@param parentGO UnityEngine.GameObject
---@param childPath string
---@return UnityEngine.UI.Image
function gohelper.findChildImage(parentGO, childPath)
    return gohelper.findChildComponent(parentGO, childPath, gohelper.Type_Image)
end

---@param parentGO UnityEngine.GameObject
---@param name string
---@return UnityEngine.GameObject
function gohelper.create2d(parentGO, name)
    return GameObjectHelper.Create(parentGO, name, true)
end

---@param parentGO UnityEngine.GameObject
---@param name string
---@return UnityEngine.GameObject
function gohelper.create3d(parentGO, name)
    return GameObjectHelper.Create(parentGO, name, false)
end

---@param sourceGO UnityEngine.GameObject
---@param parentGO UnityEngine.GameObject
---@param name string
---@return UnityEngine.GameObject
function gohelper.clone(sourceGO, parentGO, name)
    return GameObjectHelper.Clone(sourceGO, parentGO, name)
end

-- 原地克隆（parent为sourceGO的父节点）
---@param sourceGO UnityEngine.GameObject
---@param name string
---@return UnityEngine.GameObject
function gohelper.cloneInPlace(sourceGO, name)
    return GameObjectHelper.CloneInPlace(sourceGO, name)
end

-- 由项目重写此方法决定如何播音效
---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.ButtonWrap
function gohelper.findChildButtonWithAudio(go, childPath)
    return ButtonWrap.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.ButtonWrap
function gohelper.findChildButton(go, childPath)
    return ButtonWrap.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.InputFieldWrap
function gohelper.findChildInputField(go, childPath)
    return InputFieldWrap.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.ScrollRectWrap
function gohelper.findChildScrollRect(go, childPath)
    return ScrollRectWrap.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.SliderWrap
function gohelper.findChildSlider(go, childPath)
    return SliderWrap.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.ToggleWrap
function gohelper.findChildToggle(go, childPath)
    return ToggleWrap.GetWithPath(go, childPath)
end

-- 获取动态加载image的组件
---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.SingleImage
function gohelper.findChildSingleImage(go, childPath)
    return SingleImage.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@return Framework.UGUI.SingleImage
function gohelper.getSingleImage(go)
    return SingleImage.Get(go)
end

---@param go UnityEngine.GameObject
---@param childPath string
---@return Framework.UGUI.UIClickListener
function gohelper.findChildClick(go, childPath)
    return UIClickListener.GetWithPath(go, childPath)
end

---@param go UnityEngine.GameObject
---@return Framework.UGUI.UIClickListener
function gohelper.getClick(go)
    return UIClickListener.Get(go)
end

function gohelper.findChildDropdown(go, childPath)
    return TMPDropdownWrap.GetWithPath(go, childPath)
end
----获取Unity控件的接口------------------------------------------end
return gohelper